/**
 * 图片加载管理器类
 * 用于缓存和管理已加载的图片资源，避免重复加载
 */
class ImageLoadManager {
  private map = new Map<string, HTMLImageElement>()
  async loadImageList(list: FrameInfo[]): Promise<HTMLImageElement[]> {
    const res: HTMLImageElement[] = []
    for (const item of list) {
      if (this.map.has(item.url)) {
        res.push(this.map.get(item.url))
      } else {
        const img = new Image()
        img.src = item.url
        await img.decode()
        this.map.set(item.url, img)
        res.push(img)
      }
    }
    return res
  }
  removeImage(url: string) {
    if (!this.map.has(url)) return
    const value = this.map.get(url)
    value.remove()
    this.map.delete(url)
  }
}
export default new ImageLoadManager()
